package _74

func findMaxForm(strs []string, m int, n int) int {

	var dp [][]int
	for i := 0; i <= m; i++ {
		dp = append(dp, make([]int, n+1))
	}

	for _, str := range strs {
		//fmt.Printf("%v %v \n",  str, countZeroesones(str))
		count := countZeroesones(str)
		for zeroes := m; zeroes >= count[0]; zeroes-- {
			for ones := n; ones >= count[1]; ones-- {
				dp[zeroes][ones] = max(1+dp[zeroes-count[0]][ones-count[1]], dp[zeroes][ones])
			}
		}
	}

	return dp[m][n]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func countZeroesones(str string) []int {
	var count = make([]int, 2)

	for _, ch := range str {
		count[ch-'0']++
	}

	return count
}
